﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ByteSite.BLL
{
    public class database
    {
        private readonly DAL.Data data;
        public database()
        {
            data = new DAL.Data();
        }
        /// <summary>
        /// 创建数据库
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public bool CreateDatabase(string name)
        {
            return data.CreateDatabase(name);
        }

        /// <summary>
        /// 创建表
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="entityType"></param>
        public void CreateTable(string tableName, Type entityType)
        {
            data.CreateTable(tableName, entityType);
        }

        /// <summary>
        /// 增加列
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="columnInfo"></param>
        public void AddColumn(string tableName, DbColumnInfo columnInfo)
        {
            data.AddColumn(tableName, columnInfo);

        }

        /// <summary>
        /// 删除表
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public bool DropTable(string tableName)
        {
            return data.DropTable(tableName);
        }

        /// <summary>
        /// 删除列
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="columnName"></param>
        public bool DropColumn(string tableName, string columnName)
        {
            return DropColumn(tableName, columnName);
        }

        /// <summary>
        /// 获取所有数据库名称
        /// </summary>
        /// <returns></returns>
        public List<string> DbList()
        {
            return data.DbList();
        }

        /// <summary>
        /// 获取所有表
        /// </summary>
        /// <returns></returns>
        public List<DbTableInfo> TableList()
        {
            return data.TableList();
        }

        /// <summary>
        /// 获取所有视图
        /// </summary>
        /// <returns></returns>
        public List<DbTableInfo> ViewList()
        {
            return data.ViewList();
        }

        /// <summary>
        /// 获取所有列
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public List<DbColumnInfo> ColumnList(string tableName)
        {
            return data.ColumnList(tableName);
        }

        /// <summary>
        /// 备份数据库
        /// </summary>
        /// <param name="dbName"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public bool BackupDb(string dbName, string path)
        {
            return data.BackupDb(dbName, path);
        }

        /// <summary>
        /// 备份/复制表
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="newTableName"></param>
        /// <returns></returns>
        public bool BackupTable(string tableName, string newTableName)
        {
            return data.BackupTable(tableName, newTableName);
        }

        /// <summary>
        /// 修改表名
        /// </summary>
        /// <param name="sourceName"></param>
        /// <param name="distName"></param>
        /// <returns></returns>
        public bool RenameTable(string sourceName, string distName)
        {
            return data.RenameTable(sourceName, distName);
        }

        /// <summary>
        /// 修改列名称
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="sourceName"></param>
        /// <param name="distName"></param>
        /// <returns></returns>
        public bool RenameColumn(string tableName, string sourceName, string distName)
        {
            return data.RenameColumn(tableName, sourceName, distName);
        }
    }
}
